<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:height="http://www.w3.org/1999/xhtml" xmlns:min-height="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>合作伙伴财务监控</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
</head>

<body class="easyui-layout" style="padding:5px">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <th>统一社会信用代码：</th>
                    <td style="width:120px"><input type="hidden" name="companyType" value="2" id="companyType"/>
                        <input name="socialCode" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>公司名称：</th>
                    <td style="width:120px">
                        <input name="name" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <!--<th>创建人：</th>
                    <td style="width:120px">
                        <input name="creater" class="easyui-textbox" type="text" style="width:100px">
                    </td>-->
                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="onClear()">重置</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>

<table id="dg"> </table>
<!--TAB卡显示消费记录和充值记录-->
<div id="tabtab" class="easyui-window" title="账户明细查看" data-options="closed:true,iconCls:'icon-save',footer:'#tab_ft1'"  style="width:70%;paddin:100px;">
    <div id="tab_dl" class="easyui-tabs" style="width:500px; min-height:350px; " data-options="fit:true" >
        <div title="充值记录">
            <table  id="tab_recharge_table" width="100%" height="100%" border="1">
            </table>
        </div>
        <div title="消费记录">
            <table  id="tab_consume_table" width="100%" height="100%" border="1">
            </table>
        </div>
    </div>
    <div id="tab_ft1" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="closeWindow()" style="width:80px">关闭</a>
    </div>
</div>

<script type="text/javascript">
    var params={}//查询参数（自定义）
    $(function(){
        var dg = $('#dg').datagrid();
        var queryParams = $('#ffSearch').serializeObject();
        dg.datagrid({
            url:'/v1/api0/agent_Account/list',
            queryParams: queryParams,
            columns:[[
                {field:'accountID',checkbox:true},
                {field:'companyID',hidden:true},
                {field:'companyName',title:'合作伙伴名称',width:100},
                {field:'socialCode',title:'统一信贷码',width:100},
                {field:'type',title:'账户类型',hidden:true},
                {field:'balance',title:'平台账户余额',width:100,align:'center',formatter:function (value, row, index) {
                 return '<a href="#">'+row.balance+'</a>';
                }},
                {field:'recharge',title:'充值账户余额',width:100,align:'center',formatter:function (value, row, index) {
                 return '<a href="#">'+row.recharge+'</a>';
                }},
                {field:'profit',title:'收益账户余额',width:100,align:'center',formatter:function (value, row, index) {
                 return '<a href="#">'+row.profit+'</a>';
                }},
                {field:'internet',title:'网间账户余额',width:100,align:'center',formatter:function (value, row, index) {
                 return '<a href="#">'+row.internet+'</a>';
                }},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                {field:'action',title:'操作',width:50,formatter: function(value,row,index){
                    if(row.status == 1){
                        return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="disable(\''+row.accountID+'\')">禁用</a>  ' ;
                    }else{
                        return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="enable(\''+row.accountID+'\')">启用</a>  ';
                    }
                }}
            ]],
            title:'合作伙伴财务监控',
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: false,
            toolbar: [ {
                id: 'btnReload',
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    $("#dg").datagrid("reload");
                }
            }, '-', {
                id: 'btnEdit',
                text: '批量禁用',
                iconCls: 'icon-edit',
                handler: function () {
                   bentchDisable();
                }
            }]
        });

        $('#dg').datagrid({
	        onClickCell: function(index,field,value){
	        var rows = $('#dg').datagrid('getRows');
	        var row = rows[index];
            //1代表平台账户，2代表充值账户，3代表收益账户，4代表网间账户
            if(row.accountID=='null'||row.accountID=='undefined'||row.accountID==null){
            top.window.showMessage("该公司无账户！");
            return;
            }
	        if(field=='balance'){
                params = {accountId:row.accountID,companyID:row.companyID,account_type:'1'}
                listRecord();
	        }
	        if(field=='recharge'){
                params = {accountId:row.accountID,companyID:row.companyID,account_type:'2'}
                listRecord();
	        }
	        if(field=='profit'){
                params = {accountId:row.accountID,companyID:row.companyID,account_type:'3'}
                listRecord();
	        }
	        if(field=='internet'){
                params = {accountId:row.accountID,companyID:row.companyID,account_type:'4'}
                listRecord();
	        }
	       }
         });

        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function() {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch(){
        var queryParams = $('#ffSearch').serializeObject();
        $('#dg').datagrid({
            url:'/v1/api0/agent_Account/list',
            queryParams: queryParams
        });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
        $('#companyType').val("2");
        onSearch();
    }

    function closeWindow(){
        $('#consume').window('close');
        $('#recharge').window('close');
        $('#choose').window('close');
        $('#tabtab').window('close');
    }
    //批量禁用
    function bentchDisable(){
        var ids = [];
        var rows = $('#dg').datagrid('getSelections');
        if(!rows.length) {
            top.window.showMessage("请选择公司");
            return;
        }
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].accountID);
        }
        top.window.$.messager.confirm('确认', '您确定要禁用选择的账户吗？', function(r){
            if (r){
                var url = "/v1/api0/account/bantchDisable";
                var data = {ids: ids.join(',')};
                $.ajax(ajaxOption(url, data));
            }
        });
    }
    function disable(accountID) {
        if(accountID == ""||accountID==undefined||accountID=='null'){
        top.window.showMessage("此公司无账户！");
        }
        var url = "/v1/api0/account/disable";
        var data = {accountID: accountID};
        $.ajax(ajaxOption(url, data));
    }
    function enable(accountID) {
        if(accountID == ""||accountID==undefined||accountID=='null'){
        top.window.showMessage("此公司无账户！");
        }
        var url = "/v1/api0/account/enable";
        var data = {accountID: accountID};
        $.ajax(ajaxOption(url, data));
    }
    function ajaxOption(url, data) {
        return {
            type: "post",
            url: url,
            data: data,
            datatype: "json",
            beforeSend: function () {
                $('#dg').datagrid('loading');
            },
            success: function (data) {
                if(data.code == 200) {
                    $('#dg').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#dg').datagrid('loaded');
                }
            },
            error: function () {
                $('#dg').datagrid('loaded');
            }
        }
    }

    function listRecord(){
       var  queryParams = params;
       var dg1 = $('#tab_recharge_table').datagrid();
       dg1.datagrid({
            url:'/v1/api0/recharge_Record/list',
            queryParams:queryParams,
            columns:[[
                {field:'name',title:'充值名称',width:60},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "已完成";
                        case 2: return "进行中";
                    }
                }},
                {field:'sequenceNumber',title:'序列号',hidden:true},
                {field:'createTime',title:'创建时间',width:60,formatter: formatDateTime },
                {field:'updateTime',title:'更新时间',width:100,formatter: formatDateTime},
                {field:'creater',title:'创建人',width:100},
                {field:'createrId',title:'创建人ID',hidden:true},
                {field:'amount',title:'充值金额',width:100},
                {field:'recharge_method',title:'充值方式',width:100},
                {field:'type',title:'充值类型',width:100,hidden:true},
                {field:'remarks',title:'备注',width:100},
                {field:'accountId',title:'账户ID',hidden:true}
            ]],
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: true
        });

        //消费记录
        $('#tabtab').window('open');
        $('#tab_dl').tabs({
            onSelect:function(){
            var tab = $('#tab_dl').tabs('getSelected');
            var index = $('#tab_dl').tabs('getTabIndex',tab);
            if(index==0){
                $("#tab_recharge_table").datagrid("reload");
                }else if(index==1){
                    var dg2 = $('#tab_consume_table').datagrid();
                    dg2.datagrid({
                        url:'/v1/api0/consume_Record/list',
                        queryParams:queryParams,
                        columns:[[
                        {field:'name',title:'消费名称',width:60},
                        {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                         switch(value) {
                            case 1: return "已完成";
                            case 2: return "进行中";
                         }
                 }},
                {field:'sequenceNumber',title:'序列号',hidden:true},
                {field:'createTime',title:'创建时间',width:60},
                {field:'updateTime',title:'更新时间',width:100},
                {field:'creater',title:'创建人',width:100},
                {field:'createrId',title:'创建人ID',hidden:true},
                {field:'amount',title:'消费金额',width:100},
                {field:'consumeMethod',title:'消费方式',width:100},
                {field:'type',title:'消费类型',width:100},
                {field:'remarks',title:'备注',width:100},
                {field:'accountId',title:'账户ID',hidden:true}
            ]],
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: true
        });
}
}
});
}
</script>
</body>
</html>
